package com.smile.frame.workflow.camunda.demo.service;

import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.ProcessEngines;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.repository.Deployment;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author LGC
 * @date 2022/11/25 17:32
 */
@Slf4j
@Service
public class ProductService {

    @Resource
    private RepositoryService repositoryService;

    public void deployment() {
        // 创建 ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 获取 RepositoryService
        RepositoryService repositoryService = processEngine.getRepositoryService();
        // 使用 service 进行流程的部署,定义一个流程的名字,把bpmn和png部署到数据中
        Deployment deployment = repositoryService.createDeployment()
                .name("出差申请流程") //流程图标的名字
                .addClasspathResource("bpmn/evection.bpmn") //bpmn文件
                .addClasspathResource("bpmn/evection.png") //bpmn文件生成的
                .deploy();
        // 输出部署信息
        System.out.println("流程部署ID:" + deployment.getId());
        System.out.println("流程部署名字:" + deployment.getName());
    }
}
